namespace SerializationPerformance
{
    using System;
    using System.Runtime.Serialization;
    using Serialization;
    using WP7Contrib.Common;

    [DataContract(Name = "Product")]
    public sealed class Product : BaseModel, IEquatable<Product>
    {
        private string name;
        private string description;

        public Product() { }

        public Product(string name, string description)
        {
            Name = name;
            Description = description;
        }

        [DataMember(Name = "Name")]
        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.SetPropertyAndNotify(ref this.name, value, () => this.Name);
            }
        }

        [DataMember(Name = "Description")]
        public string Description
        {
            get
            {
                return this.description;
            }

            set
            {
                this.SetPropertyAndNotify(ref this.description, value, () => this.Description);
            }
        }
        
        public static bool operator ==(Product p1, Product p2)
        {
            return Equals(p1, p2);
        }

        public static bool operator !=(Product p1, Product p2)
        {
            return !Equals(p1, p2);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            return obj is Product && this.Equals((Product)obj);
        }

        public override int GetHashCode()
        {
            return this.CombineHashCodes(this.Name, this.Description);
        }
        
        public bool Equals(Product product)
        {
            if (ReferenceEquals(null, product))
            {
                return false;
            }

            if (this.Name != product.Name)
            {
                return false;
            }

             if (this.Description != product.Description)
            {
                return false;
            }
            
            return true;
        }
    }
}